#ifndef PARSECODE_H
#define PARSECODE_H
#define IMAGE_HEIGHT 32
#define IMAGE_WIDTH 32

#include <iostream>
#include <string>
#include <list>
#include <map>
#include <vector>
#include <iterator>
using namespace std;

class ItemResult
{
private:
	string _code;
	int _left;
	int _top;
	int _width;
	int _height;
public:
	string Code() const;
	int Left() const;
	int Top() const;
	int Width() const;
	int Height() const;
	void SetCode(string code);
	void SetLeft(int left);
	void SetTop(int top);
	void SetHeight(int height);
	void SetWidth(int width);
	ItemResult();
	ItemResult(string code,int left,int top,int width,int height);
};

class Range
{
private:	
	double _x_start;
	double _x_end;
	double _y_start;
	double _y_end;
public:
	Range();
	Range(double x_start,double x_end,double y_start,double y_end);
	Range(const Range& range);
	double X_Start() const;
	double X_End() const;
	double Y_Start() const;
	double Y_End() const;
};

class StructParam
{
private:
	string _structCode;
	int _unitCount;
	Range* _ranges;
	int _rangeCount;
public:
	StructParam(string structCode,int unitCount);
	string Code() const;
	int UnitCount() const;
	void AddRange(Range range);
	Range GetRange(int index) const;
};

class StructParams
{
private:
	static StructParams* p_sp;
	map<string,StructParam*> _structParams;
	void initialMap();
	StructParams();
public:
	StructParam* Get(string structCode);
	static StructParams* Create();
	~StructParams();
};

class CodeProcessor
{
private:
	string _code;	
public:
	CodeProcessor(string code);
	~CodeProcessor();
	list<ItemResult*>* Parse() const;
	bool CodeIsValid() const;
private:
	void doParse(int index,const Range& range,list<ItemResult*>* p_list,vector<string>* p_vector_str) const;
	void doParse(int index,vector<string>* p_vector_str) const;
	vector<string> getFromCode() const;
};
#endif